﻿//盘点 首页
var columns =
            [
                { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                { display: '盈亏单号', name: 'ProfitAndLossNo', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '仓库名称', name: 'StorehouseName', mintWidth: 100, width: 140 },
                 { display: '提交状态', name: 'BillStateName', mintWidth: 80, width: 80 },
                { display: '审核人', name: 'CheckorName', mintWidth: 80, width: 120},
                { display: '审核时间', name: 'CheckTime', mintWidth: 180, width: 180, type: 'selfDate' },
                { display: '审核状态', name: 'CheckStateName', mintWidth: 100, width: 140 },
                 { display: 'CheckState', name: 'CheckState', type: 'int', hide: 1 },
                  { display: 'BillState', name: 'BillState', type: 'int', hide: 1 },
               // { display: '是否结算', name: 'SettleState', mintWidth: 100, width: 140 },
                //{ display: '删除状态', name: 'DeleteState', mintWidth: 80, width: 140 },
                { display: '备注', name: 'Remarks', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
    initDataControls();
});

function initligerGrid() {
    manager = null;
    manager = $("#ProfitAndLossGrid").ligerGrid({
        columns: columns,
        title: '损溢报告管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
//                                    { text: '增加', click: dialogAdd, icon: 'add' },
//                                    { line: true },
                                    {text: '确认', click: modifyOperation, icon: 'modify' }, //修改
                                    { line: true },
            //                                    {text: '审核', click: audioOperation, icon: 'modify' }, //
//                                    { line: true },
//                                    {text: '审核', click: modifyOperation, icon: 'modify' },//这个才是真正的审核，但已不用
//                                    { line: true },
//                                    {text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
//                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), billNo: $("#billNo").val(), auditName: $("#auditName").val(), auditDate: $("#auditDate").val(),  EndDate: $("#EndDate").val() },
        url: "../ProfitAndLoss/GetJsonOfDatas?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Id); }
    });
}


//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString();
    dialogView(billId);
  }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../ProfitAndLoss/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
////add
//function dialogAdd() {
//    $.ligerDialog.open({ url: '../ProfitAndLoss/Add?orgCode=' + $("#HidOrgCode").val(), height: getDialogHeight(), width: getDialogWidth(), 
//    isResize: true, isHidden: false
//    });
//}
//delete
//function deleteOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
//    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
//        if (yes) {
//            if (row["CheckState"].toString() != "1") {
//                $.get("../ProfitAndLoss/Delete?billId=" + row["Id"].toString() + "&ids=all&rand=" + Math.random(), {}, function (data) {
//                    if (data != undefined && data == "9") {
//                        initligerGrid();
//                    }
//                });
//            } else {
//                $.ligerDialog.success('已审核，不能删除!');
//            }
//        }
//    });
//}
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要编辑的行!'); return; }
    if (row["CheckState"].toString() == "1") { $.ligerDialog.success('已提交，不能修改!'); return; }
    $.ligerDialog.open({ url: "../ProfitAndLoss/Add?orgCode=" + $("#HidOrgCode").val() + "&id=" + row["Id"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}



////审核 
//function audioOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) {
//        $.ligerDialog.success('请选择要确认的行!'); return;
//    }
//    $.ligerDialog.confirm('确定要确认吗？', function (yes) {
//        if (yes) {
//            if (row["CheckState"].toString() != "1") {
//                $.get("../ProfitAndLoss/Confirm?billId=" + row["Id"].toString() + "&rand=" + Math.random(), {}, function (data) {
//                    if (data != undefined && data == "9") {
//                        $.ligerDialog.success('审核成功!');
//                        initligerGrid();
//                    }
//                });
//            } else {
//                $.ligerDialog.success('已确认过，不能再确认！');
//            }
//        }
//    });
//}




//初始化时间
function initDataControls() {
    $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
    $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}